app.controller("logCtrl", function ($scope,$interval, $http, logService) {

    //----------分页参数------------
    $scope.pageRowSize = 10;
    $scope.curPage = 1;

    //-----------------------------

    $scope.object = {};
    $scope.formMode = false;
    $scope.errors = {};

    //--------------初始化菜单---------------
    $scope.initMenu = function () {
        showSecondMenu('billingManage');
        selectSecondMenu('logQuery');
    }
    $scope.initMenu();

    //---------------错误信息--------------
    $scope.requestError = function () {
        $scope.errorMessage = "unknown error!"
    };

    $scope.init = function () {
        $scope.startDate = getDateFunction(0);  //开始日期
        $scope.endDate = getDateFunction(0);    //结束日期
        $scope.loadLog();
    };

    //查询日志
    $scope.loadLog = function () {
        $scope.pageRowSize = 10;
        $scope.curPage = 1;
        loadPage(findLog, $scope, $scope.pageRowSize);
    };
    function findLog(curPage,pageRow,flag) {
        $.fn.jqLoading({ height: 100, width: 240, text: "查询中，请稍等...." });
        var params = {action:"findLog",pageNum:curPage,pageSize:pageRow};
        if(!NullOrUndefined($scope.startDate)){
            params["startDate"] = $scope.startDate;
        }
        if(!NullOrUndefined($scope.endDate)){
            params["endDate"] = $scope.endDate;
        }
        if(!NullOrUndefined($scope.operator)){
            params["operator"] = $scope.operator;
        }
        if(!NullOrUndefined($scope.content)){
            params["content"] = $scope.content;
        }
        if(!NullOrUndefined($scope.logType)){
            params["logType"] = $scope.logType;
        }
        logService.findLog(params, function (data) {
            $.fn.jqLoading("destroy");
            if (data.status == 'SUCCESS'){
                $scope.pageList = data.data.voList;
                $scope.size = $scope.pageList.pages;
                $scope.logs = $scope.pageList.list;
                if ($scope.logType == "30") {     //异常日志
                    $scope.systemErrorLog = true;
                    $scope.systemOperationLog = false;
                    $scope.systemJobLog = false;
                }else if ($scope.logType == "29") {     //JOB日志
                    $scope.systemErrorLog = false;
                    $scope.systemOperationLog = false;
                    $scope.systemJobLog = true;
                }else{     //系统操作日志
                    $scope.systemErrorLog = false;
                    $scope.systemOperationLog = true;
                    $scope.systemJobLog = false;
                }

                if ($scope.size > 0) {
                    $('.page-container').show();
                    var page = {
                        curPage: $scope.pageList.pageNum,
                        totalPage: $scope.size,
                        rowCount: $scope.pageList.total
                    };
                    if(flag){
                        $('.page-container').setPage(page);
                    }else{
                        $('.page-container').refreshPage(page);
                    }
                } else {
                    $('.page-container').hide();
                }
            } else {
                promptMsg(data.errorReason);
            }
        });
    }

    //清空，然后查询
    $scope.clear = function () {
        $scope.startDate = getDateFunction(0);  //开始日期
        $scope.endDate = getDateFunction(0);    //结束日期
        $scope.operator = "";
        $scope.content = "";
        $scope.logType = "";
        $scope.loadLog();
    };

    //显示日志详情窗口
    $scope.showAllContentsModal = function (allContent) {
        $scope.logContent = allContent;
        //模态框居中： 将事件监听的事件改成show.bs.modal 即可解决
        $('#showAllLogModal').on('show.bs.modal', centerModals("showAllLogModal"));
        $("#showAllLogModal").modal({
            backdrop: "static",//点击空白处不关闭对话框
            keyboard:false // 按esc键盘不关闭
        });
    };
    //关闭日志详情窗口
    $scope.closeAllContentsModal = function(){
        $("#showAllLogModal").modal("hide");
    };
});